//
//  MessageDetailViewController.m
//  shopping
//
//  Created by 徐双 on 2017/8/31.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "MessageDetailViewController.h"
#import "MessageDetailViewCell.h"

@interface MessageDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation MessageDetailViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"消息详情"];
    [self creationDate];
    [self creationView];
    
    
}

- (void)creationView{

    UIButton *buttonAdd = [[UIButton alloc] init];
    
    buttonAdd.frame = CGRectMake(DEF_SCREEN_WIDTH - 50, 0, 40, 40);
    [buttonAdd setTitle:@"清空" forState:UIControlStateNormal];
    [buttonAdd addTarget:self action:@selector(clearClick) forControlEvents:UIControlEventTouchUpInside];
    UIColor * color = getColor(@"333333");
    [buttonAdd setTitleColor:color forState:UIControlStateNormal];
    buttonAdd.titleLabel.font = [UIFont systemFontOfSize:13];
    UIBarButtonItem *rightItme = [[UIBarButtonItem alloc]initWithCustomView:buttonAdd];
    self.navigationItem.rightBarButtonItem = rightItme;
    self.tableView = [[UITableView alloc] init];
    
    self.tableView.delegate = self;
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    //去掉分割线
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    self.tableView.dataSource = self;
    
    [self.view addSubview:self.tableView];
    
    self.tableView.backgroundColor = [UIColor colorWithRed:243/255.0f green:244/255.0f blue:245/255.0f alpha:1.0];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MessageDetailViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    UIView *viewOf = [[UIView alloc] init];
    viewOf.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, 1);
    [self.view addSubview:viewOf];
    viewOf.backgroundColor = [UIColor colorWithRed:204 / 255.0f green:204 / 255.0f  blue:204 / 255.0f  alpha:1];
    
    self.tableView.frame = CGRectMake(0, 1, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64);

    
    
}

- (void)creationDate{
    _dataArr = [[NSMutableArray alloc] init];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    //   NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:self.msgType forKey:@"msgType"];
    
    
    [[MNetworkHandler sharedInstance]conURL:adminMymessageMsgType networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"status"]intValue]==1) {
            
            _dataArr = [returnData objectForKey:@"data"];
            NSLog(@"!!!!!!!!!!!!!!!%@", _dataArr);
            
            [self.view addSubview:self.tableView];
            [self.tableView reloadData];
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
//        
    }];
    
    
}

-(void)clearClick{
    
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    //   NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:self.msgType forKey:@"msgType"];
    
    
    [[MNetworkHandler sharedInstance]conURL:adminMymessageDelmsg networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"status"]intValue]==1) {
            
            
            [PublicFunction showAlert:nil message:@"清空成功" duration:5.0f];
            [self.navigationController popViewControllerAnimated:YES];
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
//        
    }];
    

    
    
    
    

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.dataArr.count;

}

-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 255;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MessageDetailViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.backgroundColor = [UIColor colorWithRed:243/255.0f green:244/255.0f blue:245/255.0f alpha:1.0];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if ([self.typeTitle isEqualToString:@"0"]) {
        cell.typeTitle.text = @"系统通知详情";
    }else if ([self.typeTitle isEqualToString:@"1"]){
    
        cell.typeTitle.text = @"物流通知详情";
        
    }else {
    
        cell.typeTitle.text = @"交易通知详情";
    }
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    dic = self.dataArr[indexPath.row];
    cell.createTime.text = [dic objectForKey:@"createTime"];
    cell.timeContent.text = [dic objectForKey:@"createTime"];
    cell.msgContent.text = [dic objectForKey:@"msgContent"];
    
    return cell;
    
}




@end
